﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading;
using System.Security;
using MAF.Common;
using System.Web;

namespace MAF.CRUD
{
    public class SafeCRUD<T> : ICRUD<T> where T : InfoBase
    {
        protected ICRUD<T> _Svc = null;

        #region 构造方法

        public SafeCRUD(ICRUD<T> svc)
        {
            _Svc = svc;
        }

        #endregion

        #region ICRUD<T> 成员

        public virtual void Add(T info)
        {
            if (!Thread.CurrentPrincipal.IsInRole(null))
                throw new SecurityException("您没有权限进行此项操作");

            _Svc.Add(info);
        }

        public virtual void Update(T info)
        {
            if (!Thread.CurrentPrincipal.IsInRole(null))
                throw new SecurityException("您没有权限进行此项操作");

            _Svc.Update(info);
        }

        public virtual int Delete(string ids)
        {
            if (!Thread.CurrentPrincipal.IsInRole(null))
                throw new SecurityException("您没有权限进行此项操作");

            return _Svc.Delete(ids);
        }

        public virtual T Show(Guid id)
        {
            return _Svc.Show(id);
        }

        public virtual IList<T> Index(BaseQueryVo vo)
        {
            return _Svc.Index(vo);
        }

        public BaseQueryVo ParseToQueryVo(NameValueCollection nvc)
        {
            return BaseQueryVo.Parse(nvc);
        }

        public int Count(BaseQueryVo vo)
        {
            return _Svc.Count(vo);
        }
        #endregion

    }
}
